CFLAGS=-Wall -Wextra -Og -pg
DEBUG_CFLAGS=-Wall -Wextra -g
SRC_DIR=../src
LIB_DIR=../../lib
IMAGES_DIR=../../images
BUILD_DIR=../build
BACKGROUND_IMAGE=high-rise_night.png

${BUILD_DIR}/droplet_sim: ${BUILD_DIR}/plane.o ${BUILD_DIR}/graphics.o ${BUILD_DIR}/shading.o ${BUILD_DIR}/vec.o ${BUILD_DIR}/time_xplat.o ${BUILD_DIR}/minmax_int.o ${BUILD_DIR}/droplet_sim.o copy_device_code
	gcc ${CFLAGS} -lSDL2 -lGLEW -lGL -lm -o ${BUILD_DIR}/droplet_sim ${BUILD_DIR}/droplet_sim.o ${BUILD_DIR}/plane.o ${BUILD_DIR}/graphics.o ${BUILD_DIR}/shading.o ${BUILD_DIR}/vec.o ${BUILD_DIR}/time_xplat.o ${BUILD_DIR}/minmax_int.o

${BUILD_DIR}/plane.o: ${LIB_DIR}/plane.h ${LIB_DIR}/plane.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/plane.o ${LIB_DIR}/plane.c

${BUILD_DIR}/graphics.o: ${LIB_DIR}/graphics.h ${LIB_DIR}/graphics.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/graphics.o ${LIB_DIR}/graphics.c

${BUILD_DIR}/shading.o: ${LIB_DIR}/shading.h ${LIB_DIR}/shading.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/shading.o ${LIB_DIR}/shading.c

${BUILD_DIR}/vec.o: ${LIB_DIR}/vector/vec.h ${LIB_DIR}/vector/vec.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/vec.o ${LIB_DIR}/vector/vec.c

${BUILD_DIR}/time_xplat.o: ${LIB_DIR}/time_xplat.h ${LIB_DIR}/time_xplat.c
	gcc ${CFLAGS} -c -D_POSIX_C_SOURCE=199309L -o ${BUILD_DIR}/time_xplat.o ${LIB_DIR}/time_xplat.c

${BUILD_DIR}/minmax_int.o: ${LIB_DIR}/minmax_int.h ${LIB_DIR}/minmax_int.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/minmax_int.o ${LIB_DIR}/minmax_int.c

${BUILD_DIR}/droplet_sim.o: ${SRC_DIR}/droplet_sim.c
	gcc ${CFLAGS} -c -o ${BUILD_DIR}/droplet_sim.o ${SRC_DIR}/droplet_sim.c

copy_device_code:
	cp ${LIB_DIR}/shaders/* ${LIB_DIR}/droplet.h ${BUILD_DIR}
	cp ${IMAGES_DIR}/${BACKGROUND_IMAGE} ${BUILD_DIR}/background.png

debug: CFLAGS=${DEBUG_CFLAGS}
debug: ${BUILD_DIR}/droplet_sim

clean:
	rm ${BUILD_DIR}/*
